﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace DotNetStar.TheKing.Models
{
    using DotNetStar.TheKing.Domain;
    using Infrastructure;

    /// <summary>
    /// 帖子编辑视图模型。
    /// </summary>
    public class EditContentViewModel :IValidatableModel
    {
        /// <summary>
        /// 使用频道类型初始化 <see cref="EditContentViewModel"/> 类的新示例。
        /// </summary>
        /// <param name="channel">频道类型，默认是帖子。</param>
        public EditContentViewModel()
        {
        }

        /// <summary>
        /// 附件批次id
        /// </summary>
        public int AttachmentBatchId { get; set; }

        public long Id { get; set; }

        [Display(Name = "标题")]
        [StringLength(60, ErrorMessage = "{0}不能超过{1}个字")]
        public string Subject { get; set; }

        [Display(Name = "正文")]
        public string Body { get; set; }

        /// <summary>
        /// 保存为草稿
        /// </summary>
        public bool IsDraft { get; set; }

        /// <summary>
        /// 频道Id
        /// </summary>
        public Channels Channel { get; set; }

        public bool IsOriginal { get; set; }

        public string Url { get; set; }
        public int? Cost { get; set; }

        public bool OnlyInvateUser { get; set; }

        /// <summary>
        /// 分类的Id
        /// </summary>
        public int? CategoryId { get; set; }

        public int OrderNo { get; set; }

        public bool IsSecret { get; set; }

        public IEnumerable<User> InvitedUsers { get; set; } = new HashSet<User>();

        public IEnumerable<string> Tags { get; set; } = new HashSet<string>();

        /// <summary>
        /// 邀请的用户id集合
        /// </summary>
        public IEnumerable<long> InviteUserIds { get; set; } = new HashSet<long>();


        public bool IsAsk => this.Channel == Channels.Ask;
        public bool IsCode => this.Channel == Channels.Code;
        public bool IsContent => this.Channel == Channels.Content;

        public bool IsVideo => this.Channel == Channels.Video;

        public bool IsEducation => this.Channel == Channels.Education;

        public string ChannelText => this.Channel.GetDescription();

        
    }

    /// <summary>
    /// 内容回复
    /// </summary>
    /// <seealso cref="IValidatableModel" />
    public class EditContentCommentViewModel:IValidatableModel
    {
        [Display(Name ="回复内容")]
        [Required(ErrorMessage ="{0}不能为空")]
        public string Body { get; set; }

        public long ContentId { get; set; }
    }

    //public class ContentDisplayModel
    //{
    //    public long Id { get; set; }
    //    public Channels Channel { get; set; }
    //    public string Subject { get; set; }
    //    public string Instruction { get; set; }
    //    public string Body { get; set; }
    //    public DateTime PostedTime { get; set; }
    //    public string Url { get; set; }
    //    public int VisitNum { get; set; }
    //    public int LikeNum { get; set; }
    //    public bool IsOriginal { get; set; }
    //    public int Cost { get; set; }
    //    public bool IsLockComment { get; set; }
    //    public ContentStatus Status { get; set; }
    //    public int OrderNo { get; set; }
    //    /// <summary>
    //    /// 是否点过赞。
    //    /// </summary>
    //    public bool HasLike { get; set; }

    //    /// <summary>
    //    /// 是否免费
    //    /// </summary>
    //    public bool IsFree => this.Cost == 0;

    //    /// <summary>
    //    /// 评论数
    //    /// </summary>
    //    public int CommentCount { get; set; }

    //    public UserDisplayModel Author { get; set; }

    //    public int? UserCategoryId { get; set; }

    //    public bool IsSecret { get; set; }

    //    public string HumanTime => this.PostedTime.ToHumanDateTimeString();

    //    public string DateWeek => this.PostedTime.ToDateWeekString();

    //    public bool IsAsk => this.Channel == Channels.Ask;
    //    public bool IsCode => this.Channel == Channels.Code;
    //    public bool IsContent=> this.Channel == Channels.Content;

    //    public bool IsVideo=>this.Channel == Channels.Video;
    //    public bool IsEducation => this.Channel == Channels.Education;

    //    public string ChannelString => this.Channel.ToString();

    //    public IEnumerable<TagDisplayModel> Tags { get; set; } = new HashSet<TagDisplayModel>();

    //    public CommentDisplayModel BestAnswer { get; set; }

    //    public CategoryDisplayModel Category { get; set; }

    //    public IEnumerable<CommentDisplayModel> Comments { get; set; } = new HashSet<CommentDisplayModel>();

    //    public static implicit operator ContentDisplayModel(PagedCollection<ContentDisplayModel> v) => throw new NotImplementedException();
    //}

    //public class TagDisplayModel
    //{
    //    public int TagId { get; set; }
    //    public string TagName { get; set; }
    //}

    //public class CommentDisplayModel
    //{
    //    public Guid Id { get; set; }
    //    public string Body { get; set; }
    //    public UserDisplayModel Author { get; set; }

    //    public DateTime PostedTime { get; set; }
        
    //    public string HumanTime => this.PostedTime.ToHumanDateTimeString();

    //    public string DateWeek => this.PostedTime.ToDateWeekString();
    //}

    //public class BestAnswerViewModel
    //{
    //    public long ContentId { get; set; }
    //    public Guid CommentId { get; set; }
    //}

    //public class CategoryDisplayModel
    //{
    //    public int Id { get; set; }
    //    public string Name { get; set; }
    //}
}
